package com.hy.controller;

import com.hy.common.PageResult;
import com.hy.common.QueryPageBean;
import com.hy.common.Result;
import com.hy.pojo.Doctors;
import com.hy.pojo.Patienevaluation;
import com.hy.pojo.PatientInfo;
import com.hy.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    private PatientService patientService;

    @RequestMapping("/getPatient")
    public PageResult getPatient(QueryPageBean queryPageBean) {
        return patientService.getPatient(queryPageBean);
    }

    @RequestMapping("/getPatientid/{id}")
    public Result getPatientid(@PathVariable("id") Integer id) {
        return patientService.getPatientid(id);
    }

    /**
     * 查询医生信息下拉菜单
     *
     * @return
     */
    @RequestMapping("/getDoctors")
    public Result getDoctors() {
        List<Doctors> doctorsList = patientService.getDoctors();
        return new Result(true, "查询成功", doctorsList);
    }

    /**
     * 添加患者
     */
    @RequestMapping("/addPatient")
    public Result addPatient(@RequestBody PatientInfo patientInfo) {
        return patientService.addPatient(patientInfo);
    }

    @RequestMapping("/updatePatient")
    public Result updatePatient(@RequestBody PatientInfo patientInfo) {
        return patientService.updatePatient(patientInfo);
    }

    @RequestMapping("/deletePatient/{id}")
    public Result deletePatient(@PathVariable("id") Integer id) {
        try {
            return patientService.deletePatient(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "删除失败");
        }
    }

    @RequestMapping("feedback")
    public Result feedback(@RequestBody Patienevaluation patienevaluation) {
        try {
            return patientService.feedback(patienevaluation);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "反馈失败");
        }
    }
}
